﻿using RecruitStudents.Client.BLL;
using RecruitStudents.Utility;
using RecruitStudents.Utility.Helper;
using RecruitStudents.Utility.Model;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace RecruitStudents.Client.Base
{
    public partial class Base_ExamTypeForm_Option : BaseForm
    {
        ServiceBase service = new ServiceBase();
        TB_Dic_ExamType model = null;
        string DicNO = string.Empty;
        public Base_ExamTypeForm_Option(string strDicNO)
        {
            InitializeComponent();
            DicNO = strDicNO;
            if (DicNO.ToSafeString().Length > 0)
            {
                model = service.GetExamTypeModel(strDicNO);
                if (model != null)
                {
                    model.Attach();
                    //txtNO.Text = model.DicNO;
                    //txtNO.Enabled = false;
                    txtName.Text = model.DicName;
                    txtExamContent.Text = model.ExamContent;
                    txtTeacherCount.Text = model.TeacherCount.ToSafeString();
                    if (model.IsActive == "1")
                    {
                        chkIsActive.Checked = true;
                    }
                    else
                    {
                        chkIsActive.Checked = false;
                    }
                }
            }
        }

        private void btnClose_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void btnSave_Click(object sender, EventArgs e)
        {
            if (DicNO.ToSafeString().Length == 0)
            {
                //if (string.IsNullOrEmpty(txtNO.Text))
                //{
                //    DevHelper.ShowInfoMessageBox("请输入编号！");
                //    txtNO.Focus();
                //    return;
                //}
            }
            if (string.IsNullOrEmpty(txtName.Text))
            {
                DevHelper.ShowInfoMessageBox("请输入名称！");
                txtName.Focus();
                return;
            }
            if (model == null)
            {
                model = new TB_Dic_ExamType();
            }
            model.DicName = txtName.Text;
            //model.DicNO = txtNO.Text;
            model.ExamYear = SessionerHelper.SystemYear;
            model.ExamContent = txtExamContent.Text;
            model.TeacherCount = txtTeacherCount.Text.ToSafeInt();
            if (chkIsActive.Checked)
            {
                model.IsActive = "1";
            }
            else
            {
                model.IsActive = "0";
            }
            if (service.SaveExamType(model))
            {
                this.DialogResult = DialogResult.OK;
                this.Close();
            }
        }
    }
}
